package com.example.score.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class AjaxResult implements Serializable {
    // 状态码
    private Integer code;
    // 状态码描述信息
    private String message;
    // 返回的数据
    private Object data;

    /**
     *  返回成功结果
     * @param data
     * @return
     */
    public static AjaxResult success(Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(200);
        result.setMessage("");
        result.setData(data);
        return result;
    }
    public static AjaxResult success(String message) {
        AjaxResult result = new AjaxResult();
        result.setCode(200);
        result.setMessage(message);
        return result;
    }
    public static AjaxResult success(Integer code, Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMessage("");
        result.setData(data);
        return result;
    }
    public static AjaxResult success(Integer code, String message, Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    /**
     * 返回失败结果
     */
    public static AjaxResult fail(int code, String message) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

}
